package com.outsourcing.bottle.ui;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ext.SatelliteMenu;
import android.view.ext.SatelliteMenu.SateliteClickedListener;
import android.view.ext.SatelliteMenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.outsourcing.bottle.BasicActivity;
import com.outsourcing.bottle.R;
import com.outsourcing.bottle.db.LoginUserInfoTable;
import com.outsourcing.bottle.db.PushNoticeInfoTable;
import com.outsourcing.bottle.domain.ExFeedEntry;
import com.outsourcing.bottle.domain.ExFeedPicEntry;
import com.outsourcing.bottle.domain.ExPicFeedEntry;
import com.outsourcing.bottle.domain.ExPicOuidInfoEntry;
import com.outsourcing.bottle.domain.ExPicSessionEntry;
import com.outsourcing.bottle.domain.ExchangePicInfo;
import com.outsourcing.bottle.domain.LoginUserInfoEntry;
import com.outsourcing.bottle.domain.PushNoticeInfo;
import com.outsourcing.bottle.domain.UrlConfig;
import com.outsourcing.bottle.remoteimage.RemoteImageView;
import com.outsourcing.bottle.ui.fragment.ExchangeFragment;
import com.outsourcing.bottle.util.AppContext;
import com.outsourcing.bottle.util.BasicUIEvent;
import com.outsourcing.bottle.util.HttpUtils;
import com.outsourcing.bottle.util.ImageLoader;
import com.outsourcing.bottle.util.ServiceUtils;
import com.outsourcing.bottle.util.TextUtil;
import com.outsourcing.bottle.util.UICore;
import com.outsourcing.bottle.widget.CustomPopupWindow;
import com.outsourcing.bottle.widget.TryRefreshableView;

public class ExchangePicDetailActivity extends BasicActivity implements
		BasicUIEvent, Callback, OnClickListener {

	private static final int EXEU_EXCHANGE_PIC_INFO = 0;
	private static final int EXEU_EXCHANGE_PIC_INFO_FAILED = 1;
	private static final int EXEU_INVISIBLE_PICEX_SUCCESS = 2;
	private static final int EXEU_INVISIBLE_PICEX_FAILED = 3;
	private static final int EXEU_REJECT_PICEX_SUCCESS = 4;
	private static final int EXEU_REJECT_PICEX_FAILED = 5;
	private static final int EXEU_VISIBLE_PICEX_SUCCESS = 6;
	private static final int EXEU_VISIBLE_PICEX_FAILED = 7;
	private static final int EXEU_REFRESH_PIC_INFO = 8;
	private static final int EXEU_UNLIKE_OPERATION = 9;
	private static final int EXEU_LIKE_OPERATION = 10;
	private static final int EXEU_LIKE_OP_PICEX_SUCCESS = 11;
	private static final int EXEU_LIKE_OP_PICEX_FAILED = 12;
	private static final int EXEU_GET_MORE_PIC_INFO = 13;
	
	private static final int INIT_HAS_EXS_ERROR = 14;
	private static final int EXEU_GOTO_PROFILE = 15;
	private static final int INIT_HAS_EXS_PROFILE = 16;
	private static final int EXEU_GOTO_EXCHANGE = 17;
	private static final int EXEU_DELETE_LOCATION_PIC_FEED = 18;
	private static final int EXEU_DELETE_LOCATION_PIC_FEED_SUCCESS = 19;
	private static final int EXEU_DELETE_LOCATION_FAILED = 20;
	private static final int EXEU_DELETE_LOCATION_FEED = 21;
	private static final int EXEU_SET_BTPIC_PAINT = 22;
	
	private final int menu_uploadphoto = 105;
	private final int menu_exprofile = 104;
	private final int menu_exphoto = 103;
	private final int menu_gainbt = 102;
	private final int menu_sendbt = 101;
	private final int user_baseinfo_notfull = 100;

	
	private final int complete_info = 1;
	
	private Handler handler;
	private ImageView topbar_back;
	private ImageView topbar_menu;
	private View mLikeView;
	private CustomPopupWindow mLikePopview;

	private int page = 1, ouid;
	private ExchangePicInfo mExPicInfo = null;
	private ImageLoader imageLoader = null;
	public int exsid;

	private TryRefreshableView rv;
	private LinearLayout ll_content;
	private ScrollView sv;
	private LinearLayout feed_comment;// 会话回复
	
//	private ImageView messageView;
	private LinearLayout bottomLayout;
	private RemoteImageView avatarView;
	private TextView contentView;
	private TextView btnCount;
	private int newNoticeCount;
	private int newMessageCount;
	private int newBottleFeedCount;
	private int newExchangeFeedCount;
	private int newMaybeKownCount;
	private String message_content;
	private String message_avatar;
	private PushBroadcastReceiver receiver;
	private PushNoticeInfo pushInfo;

	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(R.layout.exchange_pic_root);
		handler = new Handler(this);
		page = getIntent().getIntExtra("page", 1);
		ouid = getIntent().getIntExtra("ouid", 0);
		imageLoader = new ImageLoader(this, AppContext.BottleTimelineIcon);
		initLayout();
		initLikePopupWindow();
		initSateMenu();
		UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
	}

	private void initLayout() {
		topbar_back = (ImageView) findViewById(R.id.topbar_back);
		topbar_back.setOnClickListener(this);
		topbar_menu = (ImageView) findViewById(R.id.topbar_menu);
		topbar_menu.setVisibility(View.VISIBLE);
		topbar_menu.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ExchangePicDetailActivity.this, HomeActivity.class);
				intent.putExtra("currentItem", 0);
				startActivity(intent);
				finish();
			}
		});
//		messageView = (ImageView) findViewById(R.id.notice_message_count);
//		messageView.setOnClickListener(this);
		bottomLayout = (LinearLayout) findViewById(R.id.notice_bottom_layout);
		bottomLayout.setOnClickListener(this);
		avatarView = (RemoteImageView) findViewById(R.id.notice_avatar);
		contentView = (TextView) findViewById(R.id.notice_text);
		btnCount = (TextView) findViewById(R.id.notice_number);
//		messageView.setVisibility(View.VISIBLE);
		// refresh_view = (ElasticScrollView) findViewById(R.id.refresh_view);
		// refresh_view
		// .setonRefreshListener(new ElasticScrollView.OnRefreshListener() {
		//
		//
		// @Override
		// public void onRefresh() {
		// // new NewDataTask().execute();
		// page = 1;
		// UICore.eventTask(ExchangePicDetailActivity.this,
		// ExchangePicDetailActivity.this, EXEU_REFRESH_PIC_INFO, null, null);
		// }
		// });

		sv = (ScrollView) findViewById(R.id.trymySv);
		rv = (TryRefreshableView) findViewById(R.id.trymyRV);
		rv.mfooterView = (View) findViewById(R.id.tryrefresh_footer);
		rv.sv = sv;
		ll_content = (LinearLayout) findViewById(R.id.ll_content);
		// 隐藏mfooterView
		rv.mfooterViewText = (TextView) findViewById(R.id.tryrefresh_footer_text);
		rv.mfooterViewText.setVisibility(View.INVISIBLE);

		// 监听是否加载刷新
		rv.setRefreshListener(new TryRefreshableView.RefreshListener() {

			@Override
			public void onRefresh() {
				if (rv.mRefreshState == 4) {
					page = 1;
					UICore.eventTask(ExchangePicDetailActivity.this,
							ExchangePicDetailActivity.this,
							EXEU_REFRESH_PIC_INFO, null, null);
				} else if (rv.mfooterRefreshState == 4) {
					page++;
					UICore.eventTask(ExchangePicDetailActivity.this,
							ExchangePicDetailActivity.this,
							EXEU_GET_MORE_PIC_INFO, null, null);
				}

			}
		});

	}

	
	private void initSateMenu() {
		SatelliteMenu menu = (SatelliteMenu) findViewById(R.id.menu);
		menu.setVisibility(View.VISIBLE);
		if (CanvasWidth >= 480) {
			menu.setSatelliteDistance(200);
		} else {
			menu.setSatelliteDistance(100);
		}
		List<SatelliteMenuItem> items = new ArrayList<SatelliteMenuItem>();
		items.add(new SatelliteMenuItem(menu_exprofile,
				R.drawable.menu_exprofile));
		items.add(new SatelliteMenuItem(menu_exphoto, R.drawable.menu_exphoto));
		items.add(new SatelliteMenuItem(menu_gainbt, R.drawable.menu_gainbt));
		items.add(new SatelliteMenuItem(menu_sendbt, R.drawable.menu_sendbt));
		items.add(new SatelliteMenuItem(menu_uploadphoto, R.drawable.menu_uploadphoto));
		menu.addItems(items);
		menu.setOnItemClickedListener(new SateliteClickedListener() {

			public void eventOccured(int id) {
				switch (id) {
				case menu_sendbt: // 扔瓶子
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent throwIntent = new Intent(
										ExchangePicDetailActivity.this,
										ChooseBottleActivity.class);
								throwIntent.putExtra("type", "throw");
								startActivity(throwIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_gainbt: // 捞瓶子
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent tryIntent = new Intent(
										ExchangePicDetailActivity.this,
										ChooseBottleActivity.class);
								tryIntent.putExtra("type", "try");
								startActivity(tryIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_exphoto: // 交换照片
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent exchangeInfoIntent = new Intent(
										ExchangePicDetailActivity.this,
										ChooseFriendActivity.class);
								exchangeInfoIntent
										.putExtra(
												"choose_friend_type",
												AppContext.CHOOSE_FRIEND_EXCHANGE_PHOTO_TYPE);
								startActivity(exchangeInfoIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_exprofile: // 交换资料
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								LoginUserInfoTable userTable = new LoginUserInfoTable();
								LoginUserInfoEntry userEntry = userTable
										.getLoginUserInfo(AppContext
												.getInstance().getLogin_uid());
								if (userEntry.getBasicinfo_fullfill() == 0) {
									handler.sendEmptyMessage(user_baseinfo_notfull);
								} else {
									Intent exchangeFileIntent = new Intent(
											ExchangePicDetailActivity.this,
											ChooseFriendActivity.class);
									exchangeFileIntent
											.putExtra(
													"choose_friend_type",
													AppContext.CHOOSE_FRIEND_EXCHANGE_INFO_TYPE);
									startActivity(exchangeFileIntent);
								}
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_uploadphoto:
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent intent = new Intent(ExchangePicDetailActivity.this, ExpandEditActivity.class);
								Bundle extras = new Bundle();
								extras.putString("from_type", AppContext.UPLOAD_PHOTO);
								extras.putInt("albumid", 0);
								extras.putInt("ouid", AppContext.getInstance().getLogin_uid());
								intent.putExtras(extras);
								startActivity(intent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				default:
					break;
				}
			}
		});
	}

	View view = null;
	private int picid;

	private void setViewValue() {
		view = LayoutInflater.from(this).inflate(R.layout.exchange_pic_content, null);
		RemoteImageView iv_ovatar = (RemoteImageView) view.findViewById(R.id.iv_author_photo);
		TextView tv_onickname = (TextView) view.findViewById(R.id.tv_onickname);
		ImageView bt_sex = (ImageView)view.findViewById(R.id.bt_sex);
		TextView tv_oDoing = (TextView) view.findViewById(R.id.tv_odoing);
		TextView tv_oLocation = (TextView) view.findViewById(R.id.tv_olocation);
		Button bt_profile = (Button) view.findViewById(R.id.bt_profile);
		Button bt_album = (Button) view.findViewById(R.id.bt_ex_photo);
		Button bt_ExProfile = (Button) view.findViewById(R.id.bt_ex_profile);
		bt_ExProfile.setText(TextUtil.R("exchange_bt_ex_profile"));
		RemoteImageView iv_ovatar_2 = (RemoteImageView) view
				.findViewById(R.id.iv_ex_pic_ovatar_2);
		ImageView iv_ex_type = (ImageView) view.findViewById(R.id.iv_ex_type);
		TextView tv_ex_feed = (TextView) view.findViewById(R.id.tv_ex_feed);
		TextView tv_feed_time = (TextView) view.findViewById(R.id.tv_feed_time);
		TextView tv_feed_num = (TextView) view
				.findViewById(R.id.comments_ellipsis_text);
		RemoteImageView iv_ovatar_right = (RemoteImageView) view
				.findViewById(R.id.iv_ex_pic_ovatar_3);
		Button bt_ex_comment = (Button) view
				.findViewById(R.id.bt_exchange_comment);
		Button bt_ex_reject = (Button) view
				.findViewById(R.id.bt_exchange_reject);
		Button bt_ex_visible = (Button) view
				.findViewById(R.id.bt_exchange_visible);
		Button bt_ex_invisible = (Button) view
				.findViewById(R.id.bt_exchange_invisible);

		View line_comments_ellipsis = (View) view
				.findViewById(R.id.line_comments_ellipsis);
		View line_exchange_comment = (View) view
				.findViewById(R.id.line_exchange_comment);
		
		RelativeLayout feed_comments_more = (RelativeLayout) view
				.findViewById(R.id.feed_comments_more);
		feed_comment = (LinearLayout) view
				.findViewById(R.id.ll_feed_comment_layout);

		final ExPicOuidInfoEntry exPicOuidEntry = mExPicInfo.getOuid_info();
		iv_ovatar.setDefaultImage(R.drawable.avatar_default_small);
		iv_ovatar.setImageUrl(exPicOuidEntry.getOavatar());
		iv_ovatar.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent spaceIntent = new Intent(ExchangePicDetailActivity.this, UserSpaceActivity.class);
				spaceIntent.putExtra("ouid", ouid);
				startActivity(spaceIntent);
			}
		});
		String onickname = null;
		if (ouid!= AppContext.getInstance()
				.getLogin_uid()) {
			onickname ="<font color='#DA4A37'>"
				+ exPicOuidEntry.getOnickname() + "</font>";
		} else {
			onickname = "<font color='#3F99D8'>"
					+ exPicOuidEntry.getOnickname() + "</font>";
		}
//		String sex = exPicOuidEntry.getOsex() == 1 ? ("("
//				+ TextUtil.R("login_txt_register_male") + ")") : ("("
//				+ TextUtil.R("login_txt_register_female") + ")");
		tv_onickname.setText(Html.fromHtml(onickname));
		int sex_res = exPicOuidEntry.getOsex() == 1 ? R.drawable.male:R.drawable.female;
		bt_sex.setBackgroundResource(sex_res);
		if (null != exPicOuidEntry.getOdoing()
				&& exPicOuidEntry.getOdoing().length() > 0) {
			tv_oDoing.setVisibility(View.VISIBLE);
			String commentMood =  TextUtil.R("ex_comment_mood");
			tv_oDoing.setText(commentMood+ TextUtil.htmlEncode(exPicOuidEntry.getOdoing()));
		} else {
			tv_oDoing.setVisibility(View.GONE);
		}
		if ((null != exPicOuidEntry.getOcountry() && exPicOuidEntry
				.getOcountry().length() > 0)
				|| (null != exPicOuidEntry.getOcity() && exPicOuidEntry
						.getOcity().length() > 0)) {
			tv_oLocation.setVisibility(View.VISIBLE);
			tv_oLocation.setText(exPicOuidEntry.getOcountry()
					+ exPicOuidEntry.getOcity());
		} else {
			tv_oLocation.setVisibility(View.GONE);
		}
		bt_profile.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ExchangePicDetailActivity.this, UserSpaceActivity.class);
				intent.putExtra("ouid", ouid);
				startActivity(intent);
			}
		});
		bt_ExProfile.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				LoginUserInfoTable userTable = new LoginUserInfoTable();
				LoginUserInfoEntry userEntry = userTable.getLoginUserInfo(AppContext.getInstance().getLogin_uid());
				if (userEntry.getBasicinfo_fullfill() == 0) {
					handler.sendEmptyMessage(user_baseinfo_notfull);
				} else {
					doExchange(ouid);
				}	
			
			}
		});
		if (exPicOuidEntry.getOalbum_visible() == 1) {
			bt_album.setBackgroundResource(R.drawable.btn_blue_try);
			bt_album.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent(ExchangePicDetailActivity.this,
							AlbumsActivity.class);
					intent.putExtra("ouid", ouid);
					startActivity(intent);
				}
			});
		} else {
			bt_album.setBackgroundResource(R.drawable.btn_gray_try);
			bt_album.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ExchangePicDetailActivity.this.onToast(TextUtil
							.R("exchange_feed_invisible_tips"));
				}
			});
		}

		final ExPicSessionEntry exSessionEntry = mExPicInfo.getExs_info();
		iv_ovatar_2.setDefaultImage(R.drawable.avatar_default_small);
		iv_ovatar_2.setImageUrl(exSessionEntry.getExs_avatar());
		
		iv_ovatar_right.setDefaultImage(R.drawable.avatar_default_small);
		iv_ovatar_right.setImageUrl(exSessionEntry.getExs_oavatar());
		
		iv_ovatar_2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent spaceIntent = new Intent(ExchangePicDetailActivity.this, UserSpaceActivity.class);
				spaceIntent.putExtra("ouid", exSessionEntry.getExs_uid());
				startActivity(spaceIntent);
			}
		});
		iv_ovatar_right.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent spaceIntent = new Intent(ExchangePicDetailActivity.this, UserSpaceActivity.class);
				spaceIntent.putExtra("ouid", exSessionEntry.getExs_ouid());
				startActivity(spaceIntent);
			}
		});
		iv_ex_type.setImageResource(R.drawable.btn_exphoto);
	
		String mSuccess = (exSessionEntry.getExs_success() == 1) ? ("<font color='#FF3333'>"
				+ TextUtil.R("exchange_success") + "</font>")
				: ("<font color='#DA4A37'>" + TextUtil.R("exchange_failed") + "</font>");
		String nickName = null;
		if (ouid!= AppContext.getInstance().getLogin_uid()) {
			nickName ="<font color='#DA4A37'>"
				+ exSessionEntry.getExs_nickname() + "</font>";
		} else {
			nickName = "<font color='#3F99D8'>"
						+ exSessionEntry.getExs_nickname() + "</font>";
		}
		tv_ex_feed.setText(Html.fromHtml(nickName
				+ exSessionEntry.getExs_firstfeed() + " " + mSuccess));

		if (null != tv_feed_time && tv_feed_time.length() > 0) {
			tv_feed_time.setVisibility(View.VISIBLE);
			String time = "<font color='#000000'>" + " #"
					+ exSessionEntry.getExs_firstfeedtime() + "</font>";
			tv_feed_time.setText(Html.fromHtml(time));
		} else {
			tv_feed_time.setVisibility(View.GONE);
		}
		bt_ex_comment.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent commentIntent = new Intent(
						ExchangePicDetailActivity.this,
						ExpandEditActivity.class);
				Bundle commentBundle = new Bundle();
				commentBundle.putString("from_type", AppContext.REPLY_PICEX);
				commentBundle.putString("reply_picex_type", "reply");
				commentBundle.putInt("ouid", ouid);
				commentIntent.putExtras(commentBundle);
				startActivityForResult(commentIntent, 0);
			}
		});

		if (exSessionEntry.getExs_picex_rejectshow() == 1) {
			bt_ex_reject.setVisibility(View.VISIBLE);
			bt_ex_reject.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doRejectPicex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_reject.setVisibility(View.GONE);
		}
		if (exSessionEntry.getExs_picex_visibleshow() == 1) {
			bt_ex_visible.setVisibility(View.VISIBLE);
			bt_ex_visible.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doVisiblePicex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_visible.setVisibility(View.GONE);
		}
		if (exSessionEntry.getExs_picex_invisibleshow() == 1) {
			bt_ex_invisible.setVisibility(View.VISIBLE);
			bt_ex_invisible.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doInvisiblePicex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_invisible.setVisibility(View.GONE);
		}

		/******************************* 留言分割线 ***********************************/

		List<ExFeedPicEntry> mExFeedPicEntries = mExPicInfo.getExfeeds_list();
		if (null != mExFeedPicEntries && mExFeedPicEntries.size() > 0) {
			line_exchange_comment.setVisibility(View.VISIBLE);
			line_comments_ellipsis.setVisibility(View.VISIBLE);
			feed_comments_more.setVisibility(View.VISIBLE);
			tv_feed_num.setText(mExPicInfo.getRscount()+" "
					+ TextUtil.R("bottle_txt_comment_more"));
			for (int i = 0; i < mExFeedPicEntries.size(); i++) {
				final ExFeedPicEntry mExFeedPicEntry = mExFeedPicEntries.get(i);
				View feed_child = LayoutInflater.from(this).inflate(
						R.layout.exchange_comments_item, null);
				if (i == (mExFeedPicEntries.size()-1)) {
					View feed_avatar = (View) feed_child
							.findViewById(R.id.line_exchange_feed);
					feed_avatar.setVisibility(View.INVISIBLE);
				}
				TextView mFeedAvatar = (TextView) feed_child
						.findViewById(R.id.tv_feed_comment_nickname);
				String feed_nickname = null;
				if (mExFeedPicEntry.getExfeed_uid()!= AppContext.getInstance()
						.getLogin_uid()) {
					feed_nickname = (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_nickname())) ? ("<font color='#DA4A37'>"
							+ mExFeedPicEntry.getExfeed_nickname()+ "</font>")
							: "";
				} else {
					feed_nickname = (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_nickname())) ? ("<font color='#3F99D8'>"
							+ mExFeedPicEntry.getExfeed_nickname() + "</font>")
							: "";
				}
				mFeedAvatar.setText(Html.fromHtml(feed_nickname + " "
						+ mExFeedPicEntry.getExfeed_content()));
				TextView mFeedComment = (TextView) feed_child
						.findViewById(R.id.tv_feed_comment_content);
				if (null != mExFeedPicEntry.getExfeed_comment()
						&& mExFeedPicEntry.getExfeed_comment().length() > 0) {
					String feed_content = mExFeedPicEntry.getExfeed_isnew() == 1 ? ("<font color='#DA4A37'>"
							+ TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment()) + "</font>")
							: TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment());
					mFeedComment.setVisibility(View.VISIBLE);
					String commentTips = "<font color='#000000'>"
							+ TextUtil.R("exchange_feed_comment_title")
							+ "</font>";
					mFeedComment.setText(Html.fromHtml(commentTips
							+ feed_content));
				} else {
					mFeedComment.setVisibility(View.GONE);
				}
				TextView mFeedTime = (TextView) feed_child
						.findViewById(R.id.tv_feed_comment_time);
				String commentTime = TextUtils.isEmpty(mExFeedPicEntry.getExfeed_time()) ? "" : ("#" + mExFeedPicEntry.getExfeed_time());
				String commentLocation = TextUtils.isEmpty(mExFeedPicEntry.getExfeed_location()) ? "" : ("@" + mExFeedPicEntry.getExfeed_location());
				mFeedTime.setText(commentTime + " " + commentLocation);
				
				
				if (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_location())) {
					mFeedTime.setOnClickListener(new View.OnClickListener() {
						
						@Override
						public void onClick(View v) {
							
								if(mExFeedPicEntry.getLocation_delete_enable() == 1){
									final Context dialogContext = new ContextThemeWrapper(
											ExchangePicDetailActivity.this,
											android.R.style.Theme_Light);
									String[] choices = new String[2];
									choices[0] = getString(R.string.bottle_txt_check_location);
									choices[1] = getString(R.string.bottle_txt_clean_location);

									final ListAdapter adapter = new ArrayAdapter<String>(
											dialogContext,
											android.R.layout.simple_list_item_1,
											choices);

									final AlertDialog.Builder builder = new AlertDialog.Builder(
											dialogContext);
									builder.setTitle(R.string.system_info);
									builder.setSingleChoiceItems(
											adapter,
											-1,
											new DialogInterface.OnClickListener() {

												public void onClick(
														DialogInterface dialog,
														int which) {
													dialog.dismiss();
													if (which == 0) {
														dialog.dismiss();
														Intent intent = new Intent(ExchangePicDetailActivity.this,
																MapViewActivity.class);
														intent.putExtra("longitude",mExFeedPicEntry.getExfeed_lng());
														intent.putExtra("latidute", mExFeedPicEntry.getExfeed_lat());
														intent.putExtra("location", mExFeedPicEntry.getExfeed_location());
														startActivity(intent);	
													} else {
														UICore.eventTask(ExchangePicDetailActivity.this, ExchangePicDetailActivity.this, EXEU_DELETE_LOCATION_FEED, "", mExFeedPicEntry);
													}

												}
											});
									builder.create().show();
							} else {		
								
							final Context dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this,
									android.R.style.Theme_Light);
							String[] choices = new String[1];
							choices[0] = getString(R.string.bottle_txt_check_location);

							final ListAdapter adapter = new ArrayAdapter<String>(
									dialogContext,
									android.R.layout.simple_list_item_1,
									choices);

							final AlertDialog.Builder builder = new AlertDialog.Builder(
									dialogContext);
							builder.setTitle(R.string.system_info);
							builder.setSingleChoiceItems(
									adapter,
									-1,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int which) {
											dialog.dismiss();
											Intent intent = new Intent(ExchangePicDetailActivity.this,
													MapViewActivity.class);
											intent.putExtra("longitude",mExFeedPicEntry.getExfeed_lng());
											intent.putExtra("latidute", mExFeedPicEntry.getExfeed_lat());
											intent.putExtra("location", mExFeedPicEntry.getExfeed_location());
											startActivity(intent);	
										}
									});
							builder.create().show();
							
						  }
						
						}
					});	
				}
				RemoteImageView mFeedCommentAvatar = (RemoteImageView) feed_child
						.findViewById(R.id.comment_profile_photo);

				try {
					mFeedCommentAvatar.setDefaultImage(R.drawable.avatar_default_small);
					mFeedCommentAvatar.setImageUrl(mExFeedPicEntry.getExfeed_avatar());
				} catch (Exception e) {
					e.printStackTrace();
					mFeedCommentAvatar.setImageResource(R.drawable.avatar_default_small);
				}
				mFeedCommentAvatar
						.setOnClickListener(new View.OnClickListener() {

							@Override
							public void onClick(View v) {
								Intent spaceIntent = new Intent(ExchangePicDetailActivity.this, UserSpaceActivity.class);
								spaceIntent.putExtra("ouid", mExFeedPicEntry.getExfeed_uid());
								startActivity(spaceIntent);
							}
						});

				RelativeLayout exFeedPicContent = (RelativeLayout) feed_child
						.findViewById(R.id.rl_exchange_feed_type);
				if (mExFeedPicEntry.getExfeed_type() == 1) {
					exFeedPicContent.setVisibility(View.GONE);
				} else {
					if (null != mExFeedPicEntry.getExfeed_pic()
							&& mExFeedPicEntry.getExfeed_pic().length() > 0) {
						exFeedPicContent.setVisibility(View.VISIBLE);

						RelativeLayout rl_bottle_content_photo = (RelativeLayout) feed_child
								.findViewById(R.id.rl_bottle_content_photo);
						LinearLayout ll_bottle_photo_locked = (LinearLayout) feed_child
								.findViewById(R.id.ll_bottle_photo_locked);
						Button comment_button_exchange = (Button) feed_child
								.findViewById(R.id.comment_button_exchange);
						LinearLayout comment_button_like = (LinearLayout) feed_child
								.findViewById(R.id.comment_button_like);
						if (mExFeedPicEntry.getExfeed_pic_locked() == 1) {
							comment_button_like.setVisibility(View.GONE);
							rl_bottle_content_photo.setVisibility(View.GONE);
							ll_bottle_photo_locked.setVisibility(View.VISIBLE);
							comment_button_exchange.setVisibility(View.VISIBLE);
							comment_button_exchange
									.setOnClickListener(new View.OnClickListener() {

										@Override
										public void onClick(View v) {
											Intent intentPhoto = new Intent(
													ExchangePicDetailActivity.this,
													ExpandEditActivity.class);
											Bundle bundlePhoto = new Bundle();
											bundlePhoto.putString(
													"from_type",AppContext.REPLY_PICEX);
											bundlePhoto.putString("reply_picex_type", "accept");
											bundlePhoto.putInt("ouid",
													mExFeedPicEntry
															.getExfeed_uid());
											intentPhoto.putExtras(bundlePhoto);
											startActivityForResult(intentPhoto, 0);
										}
									});
						} else {
							ll_bottle_photo_locked.setVisibility(View.GONE);
							comment_button_exchange.setVisibility(View.GONE);
							rl_bottle_content_photo.setVisibility(View.VISIBLE);
							comment_button_like.setVisibility(View.VISIBLE);
							ImageView exFeedPicView = (ImageView) feed_child
									.findViewById(R.id.photo);
							imageLoader.DisplayImage(
									mExFeedPicEntry.getExfeed_pic(),
									exFeedPicView, R.drawable.album_nophoto);
							exFeedPicView
									.setOnClickListener(new View.OnClickListener() {

										@Override
										public void onClick(View v) {
											
											Status status = null;
											if (mExFeedPicEntry.getExfeed_uid()==AppContext.getInstance().getLogin_uid()) {
												 
												//自己的照片
												if (mExFeedPicEntry.getExfeed_pic_enabletuya() == 1 && mExFeedPicEntry.getExfeed_pic_allowtuya() == 1) {
													
													status = Status.exchange_pic_feed_my_allowtuya_and_enabletuya;
													
												} else if (mExFeedPicEntry.getExfeed_pic_enabletuya() == 2 && mExFeedPicEntry.getExfeed_pic_allowtuya() == 1 ) {
													status = Status.exchange_pic_feed_my_allowtuya_and_not_enabletuya;
												} else {
													status = Status.exchange_pic_feed;
												}
												
												doPhotoAction(ouid,mExFeedPicEntry, status, exsid);

											} else {
												
												if (mExFeedPicEntry.getExfeed_pic_allowtuya() == 1) {

													status = Status.exchange_pic_feed_other_allowtuya;

												} else {
													status = Status.exchange_pic_feed_other;
												}
												
												//别人的照片
												doPhotoAction(ouid,mExFeedPicEntry,
														status, exsid);

											}
											
											
											
											
										}
									});

							if (mExFeedPicEntry.getExfeed_like_enable() == 1) {
								comment_button_like.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.photo_pill));
								comment_button_like
										.setOnClickListener(new View.OnClickListener() {

											@Override
											public void onClick(View v) {
												showInfoPopupWindow(
														v,
														mExFeedPicEntry
																.getExfeed_picid(),
														ouid, exSessionEntry
																.getExsid());
											}
										});
							} else {
								comment_button_like
								.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.photo_pill_dark));
							}
							ImageView mLikeIcon = (ImageView) feed_child
									.findViewById(R.id.comment_button_like_icon);

							switch (mExFeedPicEntry.getExfeed_pic_liked()) {
							case 0:
								mLikeIcon
										.setImageResource(R.drawable.like_gray2);
								break;
							case 1:
								mLikeIcon
										.setImageResource(R.drawable.like_red2);
								break;
							case 2:
								mLikeIcon
										.setImageResource(R.drawable.like_black2);
								break;
							default:
								break;
							}
						}
					} else {
						exFeedPicContent.setVisibility(View.GONE);
					}
				}

				LinearLayout ll_exchange_feed_comment = (LinearLayout) feed_child
						.findViewById(R.id.ll_exchange_feed_comment);
				List<ExPicFeedEntry> exPicFeed = mExFeedPicEntry
						.getExpicfeeds_list();
				if (null != exPicFeed && exPicFeed.size() > 0) {
					for (int j = 0; j < exPicFeed.size(); j++) {
						final ExPicFeedEntry mExPicFeedEntry = exPicFeed.get(j);
						View picFeedItem = LayoutInflater.from(this).inflate(
								R.layout.exchange_pic_comments_item, null);
						ImageView mLink = (ImageView) picFeedItem
								.findViewById(R.id.iv_feed_comment_white);
						switch (mExPicFeedEntry.getExpicfeed_type()) {
						case 0:
							mLink.setImageResource(R.drawable.feed_white);
							break;
						case 1:
							mLink.setImageResource(R.drawable.feed_white);
							break;
						case 2:
							mLink.setImageResource(R.drawable.like_red3);
							break;
						case 3:
							mLink.setImageResource(R.drawable.like_black3);
							break;
						default:
							mLink.setImageResource(R.drawable.feed_white);
							break;
						}
						
						TextView picFeedNickname = (TextView) picFeedItem
								.findViewById(R.id.tv_feed_comment_nickname);

						String picfeedex_content = mExPicFeedEntry.getExpicfeed_isnew() == 1 ? ("<font color='#DA4A37'>"
								+ TextUtil.htmlEncode(mExPicFeedEntry.getExpicfeed_content()) + "</font>")
								: TextUtil.htmlEncode(mExPicFeedEntry.getExpicfeed_content());

						String picFeedNameStr = null;
						
						if (mExPicFeedEntry.getExpicfeed_uid() != AppContext.getInstance()
								.getLogin_uid()) {
							picFeedNameStr = (!TextUtils.isEmpty(mExPicFeedEntry.getExpicfeed_nickname())) ? ("<font color='#DA4A37'>"
									+ mExPicFeedEntry.getExpicfeed_nickname() + "</font>"): "";
						} else {
							picFeedNameStr = (!TextUtils.isEmpty(mExPicFeedEntry.getExpicfeed_nickname())) ? ("<font color='#3F99D8'>"
									+ mExPicFeedEntry.getExpicfeed_nickname() + "</font>"): "";
						}
						picFeedNickname.setText(Html.fromHtml(picFeedNameStr+ " "+ picfeedex_content));
						
						TextView picComment = (TextView) picFeedItem
								.findViewById(R.id.tv_feed_comment_content);
						if (!TextUtils.isEmpty(mExPicFeedEntry.getExpicfeed_comment())) {
							picComment.setVisibility(View.VISIBLE);
							String comment_title = "<font color='#000000'>"
									+ TextUtil.R("exchange_feed_comment_title") + "</font>";
							String feedex_content = mExPicFeedEntry.getExpicfeed_isnew()== 1 ? ("<font color='#DA4A37'>"
									+ TextUtil.htmlEncode(mExPicFeedEntry.getExpicfeed_comment()) + "</font>")
									: TextUtil.htmlEncode(mExPicFeedEntry.getExpicfeed_comment());
							
							picComment.setText(Html.fromHtml(comment_title
									+ feedex_content));
						} else {
							picComment.setVisibility(View.GONE);
						}
						final String picCommentLocation = TextUtils.isEmpty(mExPicFeedEntry.getExpicfeed_location()) ? "" : ("@" + mExPicFeedEntry.getExpicfeed_location());
						TextView picCommentTime = (TextView) picFeedItem
								.findViewById(R.id.tv_feed_comment_time);
						if (!TextUtils.isEmpty(mExPicFeedEntry
								.getExpicfeed_time())) {
							picCommentTime.setText("#"+mExPicFeedEntry
									.getExpicfeed_time()+picCommentLocation);
						}
						if (picCommentLocation.length()>0) {
							picCommentTime.setOnClickListener(new View.OnClickListener() {
								
								@Override
								public void onClick(View v) {

									if(picCommentLocation.length()>0){
										if(mExPicFeedEntry.getLocation_delete_enable_2() == 1){
											final Context dialogContext = new ContextThemeWrapper(
													ExchangePicDetailActivity.this,
													android.R.style.Theme_Light);
											String[] choices = new String[2];
											choices[0] = getString(R.string.bottle_txt_check_location);
											choices[1] = getString(R.string.bottle_txt_clean_location);

											final ListAdapter adapter = new ArrayAdapter<String>(
													dialogContext,
													android.R.layout.simple_list_item_1,
													choices);

											final AlertDialog.Builder builder = new AlertDialog.Builder(
													dialogContext);
											builder.setTitle(R.string.system_info);
											builder.setSingleChoiceItems(
													adapter,
													-1,
													new DialogInterface.OnClickListener() {

														public void onClick(
																DialogInterface dialog,
																int which) {
															dialog.dismiss();
															if (which == 0) {
																dialog.dismiss();
																Intent intent = new Intent(
																		ExchangePicDetailActivity.this,
																		MapViewActivity.class);
																intent.putExtra("longitude",
																		mExPicFeedEntry.getExpicfeed_lng());
																intent.putExtra("latidute",
																		mExPicFeedEntry.getExpicfeed_lat());
																intent.putExtra(
																		"location",
																		mExPicFeedEntry.getExpicfeed_location());
																startActivity(intent);
															} else {
																UICore.eventTask(ExchangePicDetailActivity.this, ExchangePicDetailActivity.this, EXEU_DELETE_LOCATION_PIC_FEED, "", mExPicFeedEntry);
															}

														}
													});
											builder.create().show();
									} else {
										final Context dialogContext = new ContextThemeWrapper(
												ExchangePicDetailActivity.this,
												android.R.style.Theme_Light);
										String[] choices = new String[1];
										choices[0] = getString(R.string.bottle_txt_check_location);

										final ListAdapter adapter = new ArrayAdapter<String>(
												dialogContext,
												android.R.layout.simple_list_item_1,
												choices);

										final AlertDialog.Builder builder = new AlertDialog.Builder(
												dialogContext);
										builder.setTitle(R.string.system_info);
										builder.setSingleChoiceItems(adapter, -1,
												new DialogInterface.OnClickListener() {
													public void onClick(
															DialogInterface dialog,
															int which) {
														dialog.dismiss();
														Intent intent = new Intent(
																ExchangePicDetailActivity.this,
																MapViewActivity.class);
														intent.putExtra("longitude",
																mExPicFeedEntry.getExpicfeed_lng());
														intent.putExtra("latidute",
																mExPicFeedEntry.getExpicfeed_lat());
														intent.putExtra(
																"location",
																mExPicFeedEntry.getExpicfeed_location());
														startActivity(intent);
													}
												});
										builder.create().show();
										}
									}
									
								}
							});
						}
						ll_exchange_feed_comment.addView(picFeedItem);
					}
				}
				feed_comment.addView(feed_child);
			}
		} else {
			line_exchange_comment.setVisibility(View.GONE);
			line_comments_ellipsis.setVisibility(View.GONE);
			feed_comments_more.setVisibility(View.GONE);
		}

		// refresh_view.addChild(view);
		ll_content.addView(view);
		rv.mfooterViewText.setVisibility(View.VISIBLE);
		ServiceUtils.dout("CanvasHeight:" + CanvasHeight);
		ServiceUtils.dout("ll_content.getHeight():" + ll_content.getHeight());
		ServiceUtils.dout("ll_content.getLayoutParams().height:"
				+ ll_content.getLayoutParams().height);
	}

	/** 喜欢pop */
	private void initLikePopupWindow() {

		LayoutInflater mLayoutInflater = LayoutInflater.from(this);
		mLikeView = mLayoutInflater.inflate(R.layout.pop_bottle_like, null);
		ImageView iv_unlike = (ImageView) mLikeView
				.findViewById(R.id.iv_unlike);
		ImageView iv_like = (ImageView) mLikeView.findViewById(R.id.iv_like);
		iv_unlike.setOnClickListener(this);
		iv_like.setOnClickListener(this);
		mLikePopview = new CustomPopupWindow(mLikeView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		mLikePopview.setBackgroundDrawable(getResources().getDrawable(
				R.drawable.like_frame_right));
		mLikePopview.setOutsideTouchable(true);
		mLikePopview.update();
		mLikePopview.setTouchable(true);
		mLikePopview.setFocusable(true);
	}

	public void showInfoPopupWindow(View achorView, int picid, int ouid,
			int exsid) {
		this.ouid = ouid;
		this.picid = picid;
		this.exsid = exsid;
		if (mLikePopview.isShowing()) {
			mLikePopview.dismiss();
		} else {
			// mLikePopview.showAtLocation(achorView, Gravity.RIGHT, 0, 0);
			mLikePopview.showAsDropDown(achorView, -160, -70);
		}
	}

	public void doRejectPicex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_REJECT_PICEX_SUCCESS, "", null);
	}

	private static enum Status{
		exchange_pic_feed,
		exchange_pic_feed_my_allowtuya_and_not_enabletuya,
		exchange_pic_feed_my_allowtuya_and_enabletuya,
		
		exchange_pic_feed_other,
		exchange_pic_feed_other_allowtuya,
	}
 	

	@Override
	public void execute(int mes, Object obj) {
		switch (mes) {
		case EXEU_EXCHANGE_PIC_INFO:
			getExchangePic(ouid, page);
			break;
		case EXEU_INVISIBLE_PICEX_SUCCESS:
			invisiblePicex(ouid);
			break;
		case EXEU_REJECT_PICEX_SUCCESS:
			rejectPicex(ouid);
			break;
		case EXEU_VISIBLE_PICEX_SUCCESS:
			visiblePicex(ouid);
			break;
		case EXEU_REFRESH_PIC_INFO:
			refreshExchangePic(ouid, page);
			break;
		case EXEU_UNLIKE_OPERATION:
			likeIOperationPicex(ouid, picid, 1);
			break;
		case EXEU_LIKE_OPERATION:
			likeIOperationPicex(ouid, picid, 0);
			break;
		case EXEU_GET_MORE_PIC_INFO:
			getMoreExchangePic(ouid, page);
			break;
		case EXEU_GOTO_EXCHANGE:
			getHasExs(ouid);
			break;
		case EXEU_DELETE_LOCATION_PIC_FEED:
			ExPicFeedEntry mExPicFeedEntry = (ExPicFeedEntry)obj;
			deleteLocation(String.valueOf(mExPicFeedEntry.getLocation_objtype_2()),String.valueOf(mExPicFeedEntry.getLocation_objid_2()));
			break;
		case EXEU_DELETE_LOCATION_FEED:
			ExFeedPicEntry objid2 = (ExFeedPicEntry)obj;
			deleteLocation(String.valueOf(objid2.getLocation_objtype()),String.valueOf(objid2.getLocation_objid()));
			break;
		case EXEU_SET_BTPIC_PAINT:
			int optype = (Integer)obj;
			setExpicPaint(ouid, picid, optype);
			break;
		default:
			break;
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (AppContext.getInstance().isFromExchangePicSession()) {
			AppContext.getInstance().setFromExchangePicSession(false);
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
		}
	}
	
	/**
	 * 
	 * @param ouid
	 * @param picid
	 * @param optype  设置是否允许涂鸦。选择项：不允许（0）、允许（1）
	 */
	private void setExpicPaint(int ouid, int picid,int optype) {
		StringBuffer url = new StringBuffer(UrlConfig.set_expic_paint);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&picid=" + picid);
		url.append("&optype=" + optype);
		try {
			String result = HttpUtils.doGet(url.toString());
			if (result != null) {
				JSONObject object = new JSONObject(result);
				JSONObject resultObj = object.getJSONObject("results");
				int authok = resultObj.getInt("success");
				if (authok == 0) {
					String errmsg = resultObj.getString("errmsg");
					Message msg = Message.obtain(handler, EXEU_EXCHANGE_PIC_INFO_FAILED, errmsg);
					handler.sendMessage(msg);
				} else {
					String successmsg = resultObj.getString("successmsg");
					Message msg = Message.obtain(handler, EXEU_SET_BTPIC_PAINT, successmsg);
					handler.sendMessage(msg);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * @param objtype 要清除的位置的类型：选择项：（1）瓶子动态的位置信息、（2）交换动态留言的位置信息、（3）照片评论的位置信息、（4）私信的位置信息、（5）照片的位置信息
	 * @param objid objid
	 */
	private void deleteLocation(String objtype,String objid) {
		StringBuffer url = new StringBuffer(UrlConfig.delete_location);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&objtype=" + objtype);
		url.append("&objid=" + objid);
		ServiceUtils.dout("deleteLocation url:" + url.toString());
		try {
			String result = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("deleteLocation result:" + result);
			JSONObject obj = new JSONObject(result);
			JSONObject resultObj = obj.getJSONObject("results");
			int success = resultObj.getInt("success");
			String errmsg = resultObj.getString("errmsg");
			String successmsg = resultObj.getString("successmsg");
			if (success == 1) {
				Message message = handler.obtainMessage(
						EXEU_DELETE_LOCATION_PIC_FEED_SUCCESS, successmsg);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_DELETE_LOCATION_FAILED, errmsg);
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void likeIOperationPicex(int ouid, int picid, int liketype) {
		StringBuffer url = new StringBuffer(UrlConfig.likeop_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&picid=" + picid);
		url.append("&liketype=" + liketype);

		ServiceUtils.dout("likeIOperationPicex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("likeIOperationPicex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_LIKE_OP_PICEX_SUCCESS, successmsg);
					handler.sendMessage(message);
				} else {
					Message message = handler.obtainMessage(
							EXEU_LIKE_OP_PICEX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void visiblePicex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.visible_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("visiblePicex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("visiblePicex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_VISIBLE_PICEX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_VISIBLE_PICEX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void rejectPicex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.reject_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("rejectPicex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("rejectPicex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_REJECT_PICEX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_REJECT_PICEX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doVisiblePicex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_VISIBLE_PICEX_SUCCESS, "", null);
	}
	public void doExchange(int ouid) {
		this.ouid = ouid;
		UICore.eventTask(this, this, EXEU_GOTO_EXCHANGE, "has_exs", null);
	}


	private void getHasExs(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.get_has_exs);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		try {
			String result = HttpUtils.doGet(url.toString());
			if (result != null) {
				JSONObject object = new JSONObject(result);
				JSONObject resultObj = object.getJSONObject("results");
				int authok = resultObj.getInt("authok");
				if (authok == 0) {
					String errmsg = resultObj.getString("errmsg");
					Message msg = Message.obtain(handler, INIT_HAS_EXS_ERROR,
							errmsg);
					handler.sendMessage(msg);
				} else {
					JSONObject hasExsObj = object.getJSONObject("has_exs");
					int has_infoexs = hasExsObj.getInt("has_infoexs");
					if (has_infoexs == 1) {
						handler.sendEmptyMessage(EXEU_GOTO_PROFILE);
					} else {
						handler.sendEmptyMessage(INIT_HAS_EXS_PROFILE);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void getExchangePic(int ouid, int page) {
		StringBuffer url = new StringBuffer(UrlConfig.get_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&count=10");
		url.append("&page=" + page);
		url.append("&picfeedscount=5");
		ServiceUtils.dout("getExchangePic url: " + url.toString());
		try {
			String results = HttpUtils.doGet(url.toString());
			if (results == null) {
				return;
			}
			ServiceUtils.dout("getExchangePic results:" + results);
			Gson gson = new Gson();
			mExPicInfo = gson.fromJson(results, ExchangePicInfo.class);
			if (mExPicInfo.getResults().getAuthok() == 1) {
				PushNoticeInfoTable table = new PushNoticeInfoTable();
				pushInfo = table.getPushNoticeInfo(AppContext.getInstance().getLogin_uid());
				if (null!=pushInfo) {
					newBottleFeedCount = pushInfo.getNew_btfeed_count();
					newExchangeFeedCount = pushInfo.getNew_exfeed_count();
					newMessageCount = pushInfo.getNew_message_count();
					newNoticeCount = pushInfo.getNew_notice_count();
					message_content = pushInfo.getMessage_content();
					message_avatar = pushInfo.getMessage_avatar();
					newMaybeKownCount = pushInfo.getNew_maybeknow_count();
				}
			
				Message message = handler.obtainMessage(EXEU_EXCHANGE_PIC_INFO, mExPicInfo.getResults().getErrmsg());
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_EXCHANGE_PIC_INFO_FAILED, mExPicInfo.getResults().getErrmsg());
				handler.sendMessage(message);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void getMoreExchangePic(int ouid, int page) {
		StringBuffer url = new StringBuffer(UrlConfig.get_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&count=10");
		url.append("&page=" + page);
		url.append("&picfeedscount=5");
		ServiceUtils.dout("getExchangePic url: " + url.toString());
		try {
			String results = HttpUtils.doGet(url.toString());

			if (results == null) {
				return;
			}
			ServiceUtils.dout("getExchangePic results:" + results);
			Gson gson = new Gson();
			mExPicInfo = gson.fromJson(results, ExchangePicInfo.class);
			if (mExPicInfo.getResults().getAuthok() == 1) {
				Message message = handler.obtainMessage(EXEU_GET_MORE_PIC_INFO,
						mExPicInfo.getResults().getErrmsg());
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_EXCHANGE_PIC_INFO_FAILED, mExPicInfo.getResults()
								.getErrmsg());
				handler.sendMessage(message);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	public void doPhotoAction(final int ouid, final int picid,
			final String pic_big, final String thumnail_pic, int type) {
		if (type==2) {
			final Context dialogContext = new ContextThemeWrapper(this,
					android.R.style.Theme_Light);
			String[] choices = this.getResources().getStringArray(
					R.array.exchange_pic_feed_other);

			final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			final AlertDialog.Builder builder = new AlertDialog.Builder(
					dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Photo
								byte[] tempBytes = null;
								try {
									String filename = ServiceUtils.convertUrlToFileName(thumnail_pic);
									tempBytes = ServiceUtils.readStream(new FileInputStream(new File(
											android.os.Environment.getExternalStorageDirectory() + "/" + AppContext.BottleTimelineIcon + "/" + filename)));
								} catch (Exception e) {
									e.printStackTrace();
								}
								Intent bigPicIntent = new Intent(ExchangePicDetailActivity.this, PhotoDetailActivity.class);
								bigPicIntent.putExtra("pic_big", pic_big);
								bigPicIntent.putExtra("thumbnail", tempBytes);
								ExchangePicDetailActivity.this.startActivity(bigPicIntent);
								break;
							case 1:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this, ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid", picid);
								startActivity(intent);
								break;
							case 2:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this, ExpandEditActivity.class);
								AppContext.getInstance().setFromExchangeTime(true);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type", AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid", picid);
								commentIntent.putExtras(commentBundle);
								startActivity(commentIntent);
								break;
							case 3:
								Intent friendIntent = new Intent(ExchangePicDetailActivity.this,ChooseFriendActivity.class);
								friendIntent.putExtra("choose_friend_type", AppContext.CHOOSE_FRIEND_FORWARD_PHOTO_TYPE);
								friendIntent.putExtra("picid",picid);
								friendIntent.putExtra("pic_uid",ouid);
								startActivityForResult(friendIntent, 0);
								break;
							case 4:// Cancel
								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
		}else {
			final Context dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this,
					android.R.style.Theme_Light);
			String[] choices = ExchangePicDetailActivity.this.getResources().getStringArray(
					R.array.exchange_pic_feed);

			final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			final AlertDialog.Builder builder = new AlertDialog.Builder(
					dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Photo
								byte[] tempBytes = null;
								try {
									String filename = ServiceUtils.convertUrlToFileName(thumnail_pic);
									tempBytes = ServiceUtils.readStream(new FileInputStream(new File(
											android.os.Environment.getExternalStorageDirectory() + "/" + AppContext.BottleTimelineIcon + "/" + filename)));
								} catch (Exception e) {
									e.printStackTrace();
								}
								Intent bigPicIntent = new Intent(ExchangePicDetailActivity.this, PhotoDetailActivity.class);
								bigPicIntent.putExtra("pic_big", pic_big);
								bigPicIntent.putExtra("thumbnail", tempBytes);
								ExchangePicDetailActivity.this.startActivity(bigPicIntent);
								break;
							case 1:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this,
										ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid", picid);
								startActivity(intent);
								break;
							case 2:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this,
										ExpandEditActivity.class);
								AppContext.getInstance().setFromExchangeTime(true);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type",
										AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid", picid);
								commentIntent.putExtras(commentBundle);
								startActivity(commentIntent);
								break;
							case 3:// Cancel

								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
		}

	}
	
	
	private void refreshExchangePic(int ouid, int page) {
		StringBuffer url = new StringBuffer(UrlConfig.get_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&count=20");
		url.append("&page=" + page);
		url.append("&picfeedscount=5");
		ServiceUtils.dout("getExchangePic url: " + url.toString());
		try {
			String results = HttpUtils.doGet(url.toString());

			if (results == null) {
				return;
			}
			ServiceUtils.dout("getExchangePic results:" + results);
			Gson gson = new Gson();
			mExPicInfo = gson.fromJson(results, ExchangePicInfo.class);
			if (mExPicInfo.getResults().getAuthok() == 1) {
				Message message = handler.obtainMessage(EXEU_REFRESH_PIC_INFO,
						mExPicInfo.getResults().getErrmsg());
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_EXCHANGE_PIC_INFO_FAILED, mExPicInfo.getResults()
								.getErrmsg());
				handler.sendMessage(message);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		try {
			if (receiver != null) {
				unregisterReceiver(receiver);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean handleMessage(Message msg) {
		switch (msg.what) {
		case EXEU_EXCHANGE_PIC_INFO:
			ll_content.removeAllViews();
			setViewValue();
			pushNoticeUpdateUI();
			receiver = new PushBroadcastReceiver();
			IntentFilter filter = new IntentFilter();
			filter.addAction("push");
			registerReceiver(receiver, filter);
			break;
		case EXEU_REFRESH_PIC_INFO:
			ServiceUtils.dout("refresh");
			// refresh_view.removeChild(view);
			ll_content.removeAllViews();
			setViewValue();
			rv.finishRefresh();
			// refresh_view.onRefreshComplete();
			break;
		case EXEU_EXCHANGE_PIC_INFO_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_INVISIBLE_PICEX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
			break;
		case EXEU_INVISIBLE_PICEX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_REJECT_PICEX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
			break;
		case EXEU_REJECT_PICEX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_VISIBLE_PICEX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
			break;
		case EXEU_VISIBLE_PICEX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_LIKE_OP_PICEX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_LIKE_OP_PICEX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
			break;
		case EXEU_GET_MORE_PIC_INFO:
			List<ExFeedPicEntry> mExFeedPicEntries = mExPicInfo
					.getExfeeds_list();
			if (null != mExFeedPicEntries && mExFeedPicEntries.size() > 0) {
				setMoreFeed(mExFeedPicEntries);
			} else {
				onToast(TextUtil.R("no_more_data"));
			}
			rv.finishRefresh();
			break;
		case INIT_HAS_EXS_ERROR:
			onToast((String)msg.obj);
			break;
		case EXEU_GOTO_PROFILE:
			Intent intentExchangePro = new Intent(this,
					ExchangeInfoDetailActivity.class);
			intentExchangePro.putExtra("ouid", ouid);
			intentExchangePro.putExtra("page", 1);
			startActivity(intentExchangePro);
			break;
		case INIT_HAS_EXS_PROFILE:
			Intent intentProfile = new Intent(this,
					ExpandEditActivity.class);
			Bundle bundleProfile = new Bundle();
			bundleProfile.putString("from_type", AppContext.REPLY_INFOEX);
			bundleProfile.putInt("ouid", ouid);
			bundleProfile.putString("reply_infoex_type", "apply");
			intentProfile.putExtras(bundleProfile);
			startActivity(intentProfile);
			break;
		case user_baseinfo_notfull:
			LoginUserInfoTable userTable = new LoginUserInfoTable();
			LoginUserInfoEntry userEntry = userTable.getLoginUserInfo(AppContext.getInstance().getLogin_uid());
			showChoseMes(userEntry.getBasicinfo_tip(), complete_info);
			break;
		case EXEU_DELETE_LOCATION_PIC_FEED_SUCCESS:
			onToast((String)msg.obj);
			page = 1;
			UICore.eventTask(ExchangePicDetailActivity.this, ExchangePicDetailActivity.this, EXEU_EXCHANGE_PIC_INFO, "", null);
			break;
		case EXEU_DELETE_LOCATION_FAILED:
			onToast((String)msg.obj);
			break;
		case EXEU_SET_BTPIC_PAINT:
			onToast((String)msg.obj);
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_PIC_INFO, "", null);
			break;
		default:
			break;
		}
		return false;
	}

	@Override
	public void sysMesPositiveButtonEvent(int what) {
		if (what == complete_info) {
			Intent intent = new Intent(this, SettingActivity.class);
			startActivity(intent);
		}
	}
	
	private void setMoreFeed(List<ExFeedPicEntry> mExFeedPicEntries) {

		for (int i = 0; i < mExFeedPicEntries.size(); i++) {
			final ExFeedPicEntry mExFeedPicEntry = mExFeedPicEntries.get(i);
			View feed_child = LayoutInflater.from(this).inflate(
					R.layout.exchange_comments_item, null);
			TextView mFeedAvatar = (TextView) feed_child
					.findViewById(R.id.tv_feed_comment_nickname);
			mFeedAvatar.setText(mExFeedPicEntry.getExfeed_nickname() + " "
					+ mExFeedPicEntry.getExfeed_content());
			TextView mFeedComment = (TextView) feed_child
					.findViewById(R.id.tv_feed_comment_content);
			if (null != mExFeedPicEntry.getExfeed_comment()
					&& mExFeedPicEntry.getExfeed_comment().length() > 0) {
				mFeedComment.setVisibility(View.VISIBLE);
				String commentTips = "<font color='#000000'>"
						+ TextUtil.R("exchange_feed_comment_title") + ":"
						+ "</font>";
				String feed_content = mExFeedPicEntry.getExfeed_isnew() == 1 ? ("<font color='#DA4A37'>"
						+ TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment()) + "</font>")
						: TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment());
					
				mFeedComment.setText(Html.fromHtml(commentTips
						+feed_content));
			} else {
				mFeedComment.setVisibility(View.GONE);
			}
			TextView mFeedTime = (TextView) feed_child
					.findViewById(R.id.tv_feed_comment_time);
			mFeedTime.setText(mExFeedPicEntry.getExfeed_time() + " "
					+ mExFeedPicEntry.getExfeed_location());
			
			if (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_location())) {
				mFeedTime.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						if (mExFeedPicEntry.getLocation_delete_enable() == 1) {
							final Context dialogContext = new ContextThemeWrapper(
									ExchangePicDetailActivity.this,
									android.R.style.Theme_Light);
							String[] choices = new String[2];
							choices[0] = getString(R.string.bottle_txt_check_location);
							choices[1] = getString(R.string.bottle_txt_clean_location);

							final ListAdapter adapter = new ArrayAdapter<String>(
									dialogContext,
									android.R.layout.simple_list_item_1,
									choices);

							final AlertDialog.Builder builder = new AlertDialog.Builder(
									dialogContext);
							builder.setTitle(R.string.system_info);
							builder.setSingleChoiceItems(adapter, -1,
									new DialogInterface.OnClickListener() {

										public void onClick(
												DialogInterface dialog,
												int which) {
											dialog.dismiss();
											if (which == 0) {
												dialog.dismiss();
												Intent intent = new Intent(
														ExchangePicDetailActivity.this,
														MapViewActivity.class);
												intent.putExtra(
														"longitude",
														mExFeedPicEntry
																.getExfeed_lng());
												intent.putExtra(
														"latidute",
														mExFeedPicEntry
																.getExfeed_lat());
												intent.putExtra(
														"location",
														mExFeedPicEntry
																.getExfeed_location());
												startActivity(intent);
											} else {
												UICore.eventTask(
														ExchangePicDetailActivity.this,
														ExchangePicDetailActivity.this,
														EXEU_DELETE_LOCATION_FEED,
														"",
														mExFeedPicEntry);
											}

										}
									});
							builder.create().show();
						} else {

							final Context dialogContext = new ContextThemeWrapper(
									ExchangePicDetailActivity.this,
									android.R.style.Theme_Light);
							String[] choices = new String[1];
							choices[0] = getString(R.string.bottle_txt_check_location);

							final ListAdapter adapter = new ArrayAdapter<String>(
									dialogContext,
									android.R.layout.simple_list_item_1,
									choices);

							final AlertDialog.Builder builder = new AlertDialog.Builder(
									dialogContext);
							builder.setTitle(R.string.system_info);
							builder.setSingleChoiceItems(adapter, -1,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int which) {
											dialog.dismiss();
											Intent intent = new Intent(
													ExchangePicDetailActivity.this,
													MapViewActivity.class);
											intent.putExtra("longitude",
													mExFeedPicEntry
															.getExfeed_lng());
											intent.putExtra("latidute",
													mExFeedPicEntry
															.getExfeed_lat());
											intent.putExtra(
													"location",
													mExFeedPicEntry
															.getExfeed_location());
											startActivity(intent);
										}
									});
							builder.create().show();

						}

					}
				});	
			}
			
			RemoteImageView mFeedCommentAvatar = (RemoteImageView) feed_child
					.findViewById(R.id.comment_profile_photo);

			try {
				mFeedCommentAvatar.setDefaultImage(R.drawable.avatar_default_small);
				mFeedCommentAvatar.setImageUrl(mExFeedPicEntry.getExfeed_avatar());
			} catch (Exception e) {
				e.printStackTrace();
				mFeedCommentAvatar.setImageResource(R.drawable.avatar_default_small);
			}
			mFeedCommentAvatar.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent spaceIntent = new Intent(ExchangePicDetailActivity.this, UserSpaceActivity.class);
					spaceIntent.putExtra("ouid", mExFeedPicEntry.getExfeed_uid());
					startActivity(spaceIntent);
				}
			});

			RelativeLayout exFeedPicContent = (RelativeLayout) feed_child
					.findViewById(R.id.rl_exchange_feed_type);
			if (mExFeedPicEntry.getExfeed_type() == 1) {
				exFeedPicContent.setVisibility(View.GONE);
			} else {
				if (null != mExFeedPicEntry.getExfeed_pic()
						&& mExFeedPicEntry.getExfeed_pic().length() > 0) {
					exFeedPicContent.setVisibility(View.VISIBLE);

					RelativeLayout rl_bottle_content_photo = (RelativeLayout) feed_child
							.findViewById(R.id.rl_bottle_content_photo);
					LinearLayout ll_bottle_photo_locked = (LinearLayout) feed_child
							.findViewById(R.id.ll_bottle_photo_locked);
					Button comment_button_exchange = (Button) feed_child
							.findViewById(R.id.comment_button_exchange);
					LinearLayout comment_button_like = (LinearLayout) feed_child
							.findViewById(R.id.comment_button_like);
					if (mExFeedPicEntry.getExfeed_pic_locked() == 1) {
						comment_button_like.setVisibility(View.GONE);
						rl_bottle_content_photo.setVisibility(View.GONE);
						ll_bottle_photo_locked.setVisibility(View.VISIBLE);
						comment_button_exchange.setVisibility(View.VISIBLE);
						comment_button_exchange
								.setOnClickListener(new View.OnClickListener() {

									@Override
									public void onClick(View v) {
										Intent intentPhoto = new Intent(
												ExchangePicDetailActivity.this,
												ExpandEditActivity.class);
										Bundle bundlePhoto = new Bundle();
										bundlePhoto.putString("from_type",
												AppContext.APPLY_PICEX);
										bundlePhoto
												.putInt("ouid", mExFeedPicEntry
														.getExfeed_uid());
										intentPhoto.putExtras(bundlePhoto);
										startActivity(intentPhoto);
									}
								});
					} else {
						ll_bottle_photo_locked.setVisibility(View.GONE);
						comment_button_exchange.setVisibility(View.GONE);
						rl_bottle_content_photo.setVisibility(View.VISIBLE);
						comment_button_like.setVisibility(View.VISIBLE);
						ImageView exFeedPicView = (ImageView) feed_child
								.findViewById(R.id.photo);
						imageLoader.DisplayImage(
								mExFeedPicEntry.getExfeed_pic(), exFeedPicView,
								R.drawable.album_nophoto);
						exFeedPicView
								.setOnClickListener(new View.OnClickListener() {

									@Override
									public void onClick(View v) {
										byte[] tempBytes = null;
										try {
											String filename = ServiceUtils.convertUrlToFileName(mExFeedPicEntry.getExfeed_pic());
											tempBytes = ServiceUtils.readStream(new FileInputStream(new File(
													android.os.Environment.getExternalStorageDirectory() + "/" + AppContext.BottleTimelineIcon + "/" + filename)));
										} catch (Exception e) {
											e.printStackTrace();
										}
										Intent bigPicIntent = new Intent(ExchangePicDetailActivity.this, PhotoDetailActivity.class);
										bigPicIntent.putExtra("pic_big", mExFeedPicEntry.getExfeed_pic_big());
										bigPicIntent.putExtra("thumbnail", tempBytes);
										ExchangePicDetailActivity.this.startActivity(bigPicIntent);
									}
								});

						if (mExFeedPicEntry.getExfeed_like_enable() == 1) {
							comment_button_like
									.setOnClickListener(new View.OnClickListener() {

										@Override
										public void onClick(View v) {
											showInfoPopupWindow(v,
													mExFeedPicEntry
															.getExfeed_picid(),
													ouid, mExPicInfo
															.getExs_info()
															.getExsid());
										}
									});
						} else {
							comment_button_like.setBackgroundDrawable(null);
						}
						ImageView mLikeIcon = (ImageView) feed_child
								.findViewById(R.id.comment_button_like_icon);

						switch (mExFeedPicEntry.getExfeed_pic_liked()) {
						case 0:
							mLikeIcon.setImageResource(R.drawable.like_gray2);
							break;
						case 1:
							mLikeIcon.setImageResource(R.drawable.like_red2);
							break;
						case 2:
							mLikeIcon.setImageResource(R.drawable.like_black2);
							break;
						default:
							break;
						}
					}
				} else {
					exFeedPicContent.setVisibility(View.GONE);
				}
			}

			LinearLayout ll_exchange_feed_comment = (LinearLayout) feed_child
					.findViewById(R.id.ll_exchange_feed_comment);
			List<ExPicFeedEntry> exPicFeed = mExFeedPicEntry
					.getExpicfeeds_list();
			if (null != exPicFeed && exPicFeed.size() > 0) {
				for (int j = 0; j < exPicFeed.size(); j++) {
					final ExPicFeedEntry mExPicFeedEntry = exPicFeed.get(j);
					View picFeedItem = LayoutInflater.from(this).inflate(
							R.layout.exchange_pic_comments_item, null);
					ImageView mLink = (ImageView) picFeedItem
							.findViewById(R.id.iv_feed_comment_white);
					switch (mExPicFeedEntry.getExpicfeed_type()) {
					case 0:
						mLink.setImageResource(R.drawable.feed_white);
						break;
					case 1:
						mLink.setImageResource(R.drawable.feed_white);
						break;
					case 2:
						mLink.setImageResource(R.drawable.like_red2);
						break;
					case 3:
						mLink.setImageResource(R.drawable.like_black2);
						break;
					default:
						mLink.setImageResource(R.drawable.feed_white);
						break;
					}
					TextView picFeedNickname = (TextView) picFeedItem
							.findViewById(R.id.tv_feed_comment_nickname);
					picFeedNickname.setText(mExPicFeedEntry
							.getExpicfeed_nickname()
							+ " "
							+ mExPicFeedEntry.getExpicfeed_content());

					TextView picComment = (TextView) picFeedItem
							.findViewById(R.id.tv_feed_comment_content);
					if (null != mExPicFeedEntry.getExpicfeed_comment()
							&& mExPicFeedEntry.getExpicfeed_comment().length() > 0) {
						picComment.setVisibility(View.VISIBLE);
						String comment_title = "<font color='#000000'>"
								+ TextUtil.R("exchange_feed_comment_title")
								+ ":" + "</font>";
						String feedex_content = mExPicFeedEntry.getExpicfeed_isnew()== 1 ? ("<font color='#DA4A37'>"
								+ TextUtil.htmlEncode(mExPicFeedEntry.getExpicfeed_comment()) + "</font>")
								: TextUtil.htmlEncode(mExPicFeedEntry.getExpicfeed_comment());
						
						picComment.setText(Html.fromHtml(comment_title
								+ feedex_content));
					} else {
						picComment.setVisibility(View.GONE);
					}
					final String picCommentLocation = TextUtils.isEmpty(mExPicFeedEntry.getExpicfeed_location()) ? "" : ("@" + mExPicFeedEntry.getExpicfeed_location());
					TextView picCommentTime = (TextView) picFeedItem
							.findViewById(R.id.tv_feed_comment_time);
					if (!TextUtils.isEmpty(mExPicFeedEntry
							.getExpicfeed_time())) {
						picCommentTime.setText("#"+mExPicFeedEntry
								.getExpicfeed_time()+picCommentLocation);
					}

					if (picCommentLocation.length()>0) {
						picCommentTime.setOnClickListener(new View.OnClickListener() {
							
							@Override
							public void onClick(View v) {
						
								
								if(picCommentLocation.length()>0){
									if(mExPicFeedEntry.getLocation_delete_enable_2() == 1){
										final Context dialogContext = new ContextThemeWrapper(
												ExchangePicDetailActivity.this,
												android.R.style.Theme_Light);
										String[] choices = new String[2];
										choices[0] = getString(R.string.bottle_txt_check_location);
										choices[1] = getString(R.string.bottle_txt_clean_location);

										final ListAdapter adapter = new ArrayAdapter<String>(
												dialogContext,
												android.R.layout.simple_list_item_1,
												choices);

										final AlertDialog.Builder builder = new AlertDialog.Builder(
												dialogContext);
										builder.setTitle(R.string.system_info);
										builder.setSingleChoiceItems(
												adapter,
												-1,
												new DialogInterface.OnClickListener() {

													public void onClick(
															DialogInterface dialog,
															int which) {
														dialog.dismiss();
														if (which == 0) {
															dialog.dismiss();
															Intent intent = new Intent(
																	ExchangePicDetailActivity.this,
																	MapViewActivity.class);
															intent.putExtra("longitude",
																	mExPicFeedEntry.getExpicfeed_lng());
															intent.putExtra("latidute",
																	mExPicFeedEntry.getExpicfeed_lat());
															intent.putExtra(
																	"location",
																	mExPicFeedEntry.getExpicfeed_location());
															startActivity(intent);
														} else {
															UICore.eventTask(ExchangePicDetailActivity.this, ExchangePicDetailActivity.this, EXEU_DELETE_LOCATION_PIC_FEED, "", mExPicFeedEntry);
														}

													}
												});
										builder.create().show();
								} else {
									final Context dialogContext = new ContextThemeWrapper(
											ExchangePicDetailActivity.this,
											android.R.style.Theme_Light);
									String[] choices = new String[1];
									choices[0] = getString(R.string.bottle_txt_check_location);

									final ListAdapter adapter = new ArrayAdapter<String>(
											dialogContext,
											android.R.layout.simple_list_item_1,
											choices);

									final AlertDialog.Builder builder = new AlertDialog.Builder(
											dialogContext);
									builder.setTitle(R.string.system_info);
									builder.setSingleChoiceItems(adapter, -1,
											new DialogInterface.OnClickListener() {
												public void onClick(
														DialogInterface dialog,
														int which) {
													dialog.dismiss();
													Intent intent = new Intent(
															ExchangePicDetailActivity.this,
															MapViewActivity.class);
													intent.putExtra("longitude",
															mExPicFeedEntry.getExpicfeed_lng());
													intent.putExtra("latidute",
															mExPicFeedEntry.getExpicfeed_lat());
													intent.putExtra(
															"location",
															mExPicFeedEntry.getExpicfeed_location());
													startActivity(intent);
												}
											});
									builder.create().show();
									}
								}
								
							}
						});
					}
					
					ll_exchange_feed_comment.addView(picFeedItem);
				}
			}
			feed_comment.addView(feed_child);
		}

	}

	public void doInvisiblePicex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_INVISIBLE_PICEX_SUCCESS, "", null);
	}

	private void invisiblePicex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.invisible_picex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("invisiblePicex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("invisiblePicex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_INVISIBLE_PICEX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_INVISIBLE_PICEX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent data) {
		super.onActivityResult(arg0, arg1, data);
		// refresh_view.removeChild(view);
		if (null!=data) {
			if (data.getBooleanExtra("need_refresh", false)) {
				page = 1;
				UICore.eventTask(this, this, EXEU_REFRESH_PIC_INFO, "", null);
			}	
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.topbar_back:
			finish();
			break;
		case R.id.iv_unlike:// 不喜欢
			mLikePopview.dismiss();
			UICore.eventTask(this, this, EXEU_UNLIKE_OPERATION, "", null);
			break;
		case R.id.iv_like:// 喜欢
			mLikePopview.dismiss();
			UICore.eventTask(this, this, EXEU_LIKE_OPERATION, "", null);
			break;
//		case R.id.notice_message_count:
//			doMessageAction();
//			break;
		case R.id.notice_bottom_layout:
			doFeedsAction();
			break;
		default:
			break;
		}
	}
	
	/***
	 * 最新的动态 :0 最新的动态:1 资料交换:2 照片交换:3
	 * 
	 * @param mode
	 * @param type
	 *            1：我的照片 2.别人的照片
	 */
	public void doPhotoAction(final int ouid, final ExFeedPicEntry exfeedEntry , Status status,final int exsid) {
		Context dialogContext = null;
		ListAdapter adapter = null;
		String[] choices = null;
		AlertDialog.Builder builder = null;
		switch (status) {
		case exchange_pic_feed:

			dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this, android.R.style.Theme_Light);
			choices = ExchangePicDetailActivity.this.getResources().getStringArray(
					R.array.exchange_pic_feed);

			adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			builder = new AlertDialog.Builder(dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this,
										ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								startActivity(intent);
								break;
							case 1:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this,
										ExpandEditActivity.class);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type",
										AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid",  exfeedEntry.getExfeed_picid());
								commentIntent.putExtras(commentBundle);
								startActivityForResult(commentIntent,0);
								break;
							case 2:// Cancel

								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
		
			break;
		case exchange_pic_feed_my_allowtuya_and_enabletuya:
			dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this,
					android.R.style.Theme_Light);
			choices = ExchangePicDetailActivity.this.getResources().getStringArray(
					R.array.exchange_pic_feed_my_allowtuya_and_enabletuya);

			adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			builder = new AlertDialog.Builder(
					dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this,
										ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								startActivity(intent);
								break;
							case 1:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this, ExpandEditActivity.class);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type", AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid",  exfeedEntry.getExfeed_picid());
								commentIntent.putExtras(commentBundle);
								startActivityForResult(commentIntent,0);
								break;
							case 2://涂鸦照片
								byte[] tempBytes = null;
								try {
									String filename = ServiceUtils.convertUrlToFileName(exfeedEntry.getExfeed_pic());
									tempBytes = ServiceUtils.readStream(new FileInputStream(new File(
											android.os.Environment.getExternalStorageDirectory() + "/" + AppContext.BottleTimelineIcon + "/" + filename)));
								} catch (Exception e) {
									e.printStackTrace();
								}
								Intent bigPicIntent = new Intent(ExchangePicDetailActivity.this, PhotoDetailActivity.class);
								bigPicIntent.putExtra("pic_big", exfeedEntry.getExfeed_pic_big());
								bigPicIntent.putExtra("thumbnail", tempBytes);
								bigPicIntent.putExtra("paintType", AppContext.PAINT_PICEX);
								bigPicIntent.putExtra("ouid", ouid);
								bigPicIntent.putExtra("picid", exfeedEntry.getExfeed_picid());
								bigPicIntent.putExtra("return_type",ExchangePicDetailActivity.class.getSimpleName());		
								bigPicIntent.putExtra("isToDraw", true);
								startActivity(bigPicIntent);	
								break;
							case 3://允许涂鸦
								doExpicPaint(ouid, exfeedEntry.getExfeed_picid(), 1, exsid);
								break;
							case 4:// Cancel
								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
			break;
		case exchange_pic_feed_my_allowtuya_and_not_enabletuya:
			dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this,
					android.R.style.Theme_Light);
			choices = ExchangePicDetailActivity.this.getResources().getStringArray(
					R.array.exchange_pic_feed_my_allowtuya_and_not_enabletuya);

			adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			builder = new AlertDialog.Builder(
					dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this,
										ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								startActivity(intent);
								break;
							case 1:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this, ExpandEditActivity.class);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type", AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid",  exfeedEntry.getExfeed_picid());
								commentIntent.putExtras(commentBundle);
								startActivityForResult(commentIntent,0);
								break;
							case 2://涂鸦照片
								byte[] tempBytes = null;
								try {
									String filename = ServiceUtils.convertUrlToFileName(exfeedEntry.getExfeed_pic());
									tempBytes = ServiceUtils.readStream(new FileInputStream(new File(
											android.os.Environment.getExternalStorageDirectory() + "/" + AppContext.BottleTimelineIcon + "/" + filename)));
								} catch (Exception e) {
									e.printStackTrace();
								}
								
								Intent bigPicIntent = new Intent(ExchangePicDetailActivity.this, PhotoDetailActivity.class);
								bigPicIntent.putExtra("pic_big", exfeedEntry.getExfeed_pic_big());
								bigPicIntent.putExtra("thumbnail", tempBytes);
								bigPicIntent.putExtra("paintType", AppContext.PAINT_PICEX);
								bigPicIntent.putExtra("ouid", ouid);
								bigPicIntent.putExtra("picid", exfeedEntry.getExfeed_picid());
								bigPicIntent.putExtra("return_type",ExchangePicDetailActivity.class.getSimpleName());		
								bigPicIntent.putExtra("isToDraw", true);
								startActivity(bigPicIntent);	
								break;
							case 3://不允许涂鸦
								doExpicPaint(ouid, exfeedEntry.getExfeed_picid(), 0, exsid);
								break;
							case 4:// Cancel
								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
			break;
		case exchange_pic_feed_other:

			dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this,
					android.R.style.Theme_Light);
			choices = ExchangePicDetailActivity.this.getResources().getStringArray(
					R.array.exchange_pic_feed_other);

			adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			builder = new AlertDialog.Builder(
					dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this,
										ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								startActivity(intent);
								break;
							case 1:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this, ExpandEditActivity.class);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type", AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid",  exfeedEntry.getExfeed_picid());
								commentIntent.putExtras(commentBundle);
								startActivityForResult(commentIntent,0);
								break;
							case 2://转发
								Intent friendIntent = new Intent(ExchangePicDetailActivity.this,
										ChooseFriendActivity.class);
								friendIntent.putExtra("choose_friend_type",
										AppContext.CHOOSE_FRIEND_FORWARD_PHOTO_TYPE);
								friendIntent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								friendIntent.putExtra("pic_uid", ouid);
								friendIntent.putExtra("return_type",ExchangePicDetailActivity.class.getSimpleName());	
								startActivity(friendIntent);
								break;
							case 3:// Cancel
								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
		
			break;
		case exchange_pic_feed_other_allowtuya:
			dialogContext = new ContextThemeWrapper(ExchangePicDetailActivity.this,
					android.R.style.Theme_Light);
			choices = ExchangePicDetailActivity.this.getResources().getStringArray(
					R.array.exchange_pic_feed_other_allowtuya);

			adapter = new ArrayAdapter<String>(dialogContext,
					android.R.layout.simple_list_item_1, choices);

			builder = new AlertDialog.Builder(
					dialogContext);
			builder.setTitle(R.string.system_info);
			builder.setSingleChoiceItems(adapter, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							switch (which) {
							case 0:// View Comment
								Intent intent = new Intent(ExchangePicDetailActivity.this,
										ExchangePicFeedDetailActivity.class);
								intent.putExtra("ouid", ouid);
								intent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								startActivity(intent);
								break;
							case 1:// Comment
								Intent commentIntent = new Intent(ExchangePicDetailActivity.this, ExpandEditActivity.class);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type", AppContext.REPLYPIC_PICEX);
								commentBundle.putInt("ouid", ouid);
								commentBundle.putInt("picid",  exfeedEntry.getExfeed_picid());
								commentIntent.putExtras(commentBundle);
								startActivityForResult(commentIntent,0);
								break;
							case 2://涂鸦照片
								byte[] tempBytes = null;
								try {
									String filename = ServiceUtils.convertUrlToFileName(exfeedEntry.getExfeed_pic());
									tempBytes = ServiceUtils.readStream(new FileInputStream(new File(
											android.os.Environment.getExternalStorageDirectory() + "/" + AppContext.BottleTimelineIcon + "/" + filename)));
								} catch (Exception e) {
									e.printStackTrace();
								}
								
								Intent bigPicIntent = new Intent(ExchangePicDetailActivity.this, PhotoDetailActivity.class);
								bigPicIntent.putExtra("pic_big", exfeedEntry.getExfeed_pic_big());
								bigPicIntent.putExtra("thumbnail", tempBytes);
								bigPicIntent.putExtra("paintType", AppContext.PAINT_PICEX);
								bigPicIntent.putExtra("ouid", exfeedEntry.getExfeed_uid());
								bigPicIntent.putExtra("picid", exfeedEntry.getExfeed_picid());
								bigPicIntent.putExtra("return_type",ExchangePicDetailActivity.class.getSimpleName());		
								bigPicIntent.putExtra("isToDraw", true);
								startActivity(bigPicIntent);	
								break;
							case 3:
								Intent friendIntent = new Intent(ExchangePicDetailActivity.this,
										ChooseFriendActivity.class);
								friendIntent.putExtra("choose_friend_type",
										AppContext.CHOOSE_FRIEND_FORWARD_PHOTO_TYPE);
								friendIntent.putExtra("return_type",ExchangePicDetailActivity.class.getSimpleName());		
								friendIntent.putExtra("picid",  exfeedEntry.getExfeed_picid());
								friendIntent.putExtra("pic_uid", ouid);
								startActivity(friendIntent);
								break;
							case 4:// Cancel
								break;
							default:
								break;
							}
						}
					});
			builder.create().show();
			break;
		default:
			break;
		}
	}
	

	public void doMessageAction() {
		
		final Context dialogContext = new ContextThemeWrapper(this,
				android.R.style.Theme_Light);
		String[] choices = new String[2];
		if (newNoticeCount > 0) {
			choices[0] = newNoticeCount + getString(R.string.bottle_txt_notice_list);
		} else {
			choices[0] = getString(R.string.bottle_txt_notice_list);
		}
		if (newMessageCount > 0) {
			choices[1] = newMessageCount + getString(R.string.bottle_txt_message_list);
		} else {
			choices[1] = getString(R.string.bottle_txt_message_list);
		}
	
		final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
				android.R.layout.simple_list_item_1, choices);
	
		final AlertDialog.Builder builder = new AlertDialog.Builder(
				dialogContext);
		builder.setTitle(R.string.system_info);
		builder.setSingleChoiceItems(adapter, -1,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						if (which == 0) {
							Intent intent = new Intent(ExchangePicDetailActivity.this, NoticeListActivity.class);
							startActivity(intent);
						} else {
							Intent intent = new Intent(ExchangePicDetailActivity.this, MessageListActivity.class);
							startActivity(intent);
						}
					}
				});
		builder.create().show();
	}
	
	public void doFeedsAction() {
		final Context dialogContext = new ContextThemeWrapper(this, android.R.style.Theme_Light);
		final List<String> choices = new ArrayList<String>(); 
		if (newBottleFeedCount > 0) {
			choices.add(newBottleFeedCount + getString(R.string.bottle_txt_new_bottle_feed));
		}
		if (newExchangeFeedCount > 0) {
			choices.add(newExchangeFeedCount + getString(R.string.bottle_txt_new_exchange_feed));
		}
		if (newNoticeCount > 0) {
			choices.add(newNoticeCount + getString(R.string.bottle_txt_notice_list));
		}
		if (newMessageCount > 0) {
			choices.add(newMessageCount + getString(R.string.bottle_txt_message_list));
		}
		if (newMaybeKownCount > 0) {
			choices.add(newMaybeKownCount + getString(R.string.bottle_txt_new_maybe_kown));
		}
		final ListAdapter adapter = new ArrayAdapter<String>(dialogContext, android.R.layout.simple_list_item_1, choices);
		final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
		builder.setTitle(R.string.system_info);
		builder.setSingleChoiceItems(adapter, -1,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						if (choices.get(which).indexOf(getString(R.string.bottle_txt_new_bottle_feed)) != -1) {
							Intent intent = new Intent(ExchangePicDetailActivity.this, HomeActivity.class);
							AppContext.getInstance().setCurrentItem(1);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_new_exchange_feed)) != -1) {
							Intent intent = new Intent(ExchangePicDetailActivity.this, HomeActivity.class);
							AppContext.getInstance().setCurrentItem(0);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_notice_list)) != -1) {
							Intent intent = new Intent(ExchangePicDetailActivity.this, NoticeListActivity.class);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_message_list)) != -1) {
							Intent intent = new Intent(ExchangePicDetailActivity.this, MessageListActivity.class);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_new_maybe_kown)) != -1) {
							Intent intent = new Intent(ExchangePicDetailActivity.this, HomeActivity.class);
							AppContext.getInstance().setCurrentItem(2);
							AppContext.getInstance().setGotoMaybeKown(true);
							startActivity(intent);
						}
					}
				});
		builder.create().show();
	}
	
	
	public void doExpicPaint(int ouid, int picid,int optype,int exsid){
		this.ouid = ouid;
		this.picid = picid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_SET_BTPIC_PAINT, "", optype);
	}
	
	public void pushNoticeUpdateUI() {
		if (newBottleFeedCount + newExchangeFeedCount + newMessageCount + newNoticeCount + newMaybeKownCount > 0) {
			bottomLayout.setVisibility(View.VISIBLE);
			contentView.setText(message_content);
			btnCount.setText(newBottleFeedCount + newExchangeFeedCount + newMessageCount + newNoticeCount + newMaybeKownCount  + "");
			avatarView.setDefaultImage(R.drawable.avatar_default_big);
			avatarView.setImageUrl(message_avatar);
		} else {
			bottomLayout.setVisibility(View.GONE);
		}
	}
	
	public class PushBroadcastReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			Bundle bundle = intent.getExtras();
			if (bundle != null) {
				newBottleFeedCount = bundle.getInt("bottle_feed_count");
				newExchangeFeedCount = bundle.getInt("exchange_feed_count");
				newMessageCount = bundle.getInt("message_count");
				newNoticeCount = bundle.getInt("notice_count");
				message_content = bundle.getString("message_content");
				message_avatar = bundle.getString("message_avatar");
				newMaybeKownCount = bundle.getInt("maybe_kown_count");
				pushNoticeUpdateUI();
			}
		}
	}
}
